package com.pdsu.alumni.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pdsu.alumni.common.annotation.CurrentUser;
import com.pdsu.alumni.common.annotation.NoAuthentication;
import com.pdsu.alumni.common.result.Result;
import com.pdsu.alumni.pojo.Community;
import com.pdsu.alumni.pojo.CommunityJoinExamine;
import com.pdsu.alumni.pojo.CommunityJoinexamineRelation;
import com.pdsu.alumni.pojo.User;
import com.pdsu.alumni.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Acerola
 * @since 2022-04-01
 */
@Api(tags = "社群控制层")
@RestController
@RequestMapping("/community")
public class CommunityController {
    @Autowired
    private ICommunityService communityService;
    @Autowired
    private ICommunityJoinexamineRelationService communityJoinexamineRelationService;
    @Autowired
    private ICommunityJoinExamineService communityJoinExamineService;
    @Autowired
    private ICommunityMemberRelationService communityMemberRelationService;
    @Autowired
    private ICommunityUpdateRelationService communityUpdateRelationService;
    @Autowired
    private ICommunityUpdateService communityUpdateService;

    /**
     * 添加：
     * 创建社群（只能创建一个（包括待审核），
     * 创建后默认为该社群群主并且是该社群成员，且仍可以加入别的社群）
     */
    @ApiOperation(value = "创建社群")
    @PostMapping("/")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> createCommunity(@CurrentUser User user, @RequestBody Map map) {
        Object o = map.get("map");
        Community community = JSON.parseObject(JSON.toJSONString(o), Community.class);
        community.setDeleted(1);

        QueryWrapper<Community> wrapper = new QueryWrapper<>();
        return new Result<>().success("创建" + community.getName() + "社群成功");
    }

    /**
     * 申请加入社群
     *
     * @param map
     * @return
     */

    @ApiOperation(value = "申请加入社群")
    @PostMapping("/join")
    @NoAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> joinCommunity(@RequestBody Map map) {
        CommunityJoinExamine communityJoinExamine = new CommunityJoinExamine();
        CommunityJoinexamineRelation communityJoinexamineRelation = new CommunityJoinexamineRelation();
        QueryWrapper<Community> wrapper = new QueryWrapper<>();
        return new Result<>().success("添加成功");
    }

    /**
     * 查看自己加入的社群(列表)
     *
     * @param
     * @return
     */
    @ApiOperation(value = "查看个人加入的社群")
    @GetMapping("/getJoined")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> getJoined(Integer uId) {

        return new Result<>().success();
    }

    @ApiOperation(value = "获取成员列表")
    @GetMapping("/memberList")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> getMemberList() {

        return new Result<>().success();
    }

    @ApiOperation(value = "查看每个加入的社群的成员信息")
    @GetMapping("/memberInfo")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> getMemberInfo(Integer id) {

        return new Result<>().success();
    }

    @ApiOperation(value = "查看每个加入的社群信息")
    @GetMapping("/communityInfo")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> getCommunityInfo(Integer id) {

        return new Result<>().success();
    }

    @ApiOperation(value = "查看被驳回的创建社群申请")
    @GetMapping("/createBack")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> getCreateBack() {

        return new Result<>().success();
    }

    @ApiOperation(value = "查看被驳回的申请加入社群列表")
    @GetMapping("/joinExamime")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> getjoinExamime() {

        return new Result<>().success();
    }

    @ApiOperation(value = "查看个人没有加入的社群列表")
    @GetMapping("/notJoin")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> getNotJoin() {

        return new Result<>().success();
    }

    //社群管理员

    @ApiOperation(value = "查看自己管理的社群")
    @GetMapping("/queryOwnCommunity")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> get() {

        return new Result<>().success().put(communityService.list());
    }

    @ApiOperation(value = "社群申请列表")
    @GetMapping("/joinList")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> examine() {

        return new Result<>().success().put(communityJoinExamineService.list());
    }

    @ApiOperation(value = "审核普通校友的社群申请")
    @GetMapping("/examine")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> examine(Integer id) {

        return new Result<>().success();
    }

    @ApiOperation(value = "修改社群基本信息")
    @PutMapping("/")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> examine(@RequestBody Map map) {

        return new Result<>().success();
    }

    @ApiOperation(value = "移除社群成员")
    @DeleteMapping("/")
    @RequiresAuthentication
    @ResponseBody
    @CrossOrigin
    public Result<?> updateCommunity(Integer id) {

        return new Result<>().success();
    }

    //社群群主


}
